package com.ys.controller.api.inter;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.sys.ToaNotice;
import com.ys.entity.sys.TsIndexImage;
import com.ys.util.DateUtil;
import com.ys.vo.A;

import lombok.AllArgsConstructor;
import lombok.Data;

@Controller
@RequestMapping("/api/inter/index")
public class ApiInterIndexController {
	private static final Logger logger = LoggerFactory.getLogger(ApiInterIndexController.class);
	
    @RequestMapping("/listBanner")
	@ResponseBody
	public A listBanner(HttpServletRequest request) {
		try {

			List<TsIndexImage> listTsIndexImage = new TsIndexImage()
					.setOrderby("A.Iid asc")
					.queryList();

			List<ListBannerDto.DetailDto> detailArr = new ArrayList<ListBannerDto.DetailDto>();
			for(TsIndexImage tsIndexImage : listTsIndexImage) {
				String link = tsIndexImage.getImageUrl();
				detailArr.add(new ListBannerDto.DetailDto(link));
			}

			ListBannerDto dto = new ListBannerDto(detailArr);
			return A.suc(dto);
		}catch (Exception e){
			logger.error("出错：",e.getMessage(),e);
			return A.err("系统获取信息出错！");
		}
	}
	@Data
	@AllArgsConstructor
	public static class ListBannerDto {
		
		private List<DetailDto> detailArr; // 详情数组
		
		@Data
		@AllArgsConstructor
		public static class DetailDto {
			
			private String link; // 图片链接地址
		}
	}
	
    @RequestMapping("/listNotice")
	@ResponseBody
	public A listNotice() {
		try {
			List<ToaNotice> listToaNotice = new ToaNotice()
					.setOrderby("A.Id DESC")
					.queryList();

			List<ListNoticeDto.DetailDto> detailArr = new ArrayList<ListNoticeDto.DetailDto>();
			if(listToaNotice!=null && listToaNotice.size()>0){
				for(ToaNotice toaNotice : listToaNotice) {
					Long id = toaNotice.getId();
					String title = toaNotice.getVzt();
					String content = toaNotice.getVnr();
					String createTime = DateUtil.getYYYY_MM_DD_HH_mm_ss(toaNotice.getCreateTime());
					detailArr.add(new ListNoticeDto.DetailDto(id, title, content, createTime));
				}
			}



			ListNoticeDto dto = new ListNoticeDto(detailArr);
			return A.suc(dto);
		}catch (Exception e){
			logger.error("出错：",e.getMessage(),e);
			return A.err("系统获取信息出错！");
		}
	}
	@Data
	@AllArgsConstructor
	public static class ListNoticeDto {
		
		private List<DetailDto> detailArr; // 详情数组
		
		@Data
		@AllArgsConstructor
		public static class DetailDto {
			private Long id; // 主键ID
			private String title; // 标题
			private String content; // 内容
			private String createTime; // 发布时间
		}
	}
}
